package com.liu.design.structure.component;

import java.util.Scanner;

/**
 * @author LIU
 * @version 1.0
 * @date 2024/5/6 14:31
 * @description TODO
 */
public class DiscountFactory {
    public DiscountStrategy create(String type){
        // 单一折扣策略
        if ("ynn".equals(type))  return new VipDiscount();
        if ("nyn".equals(type))  return new StoreDiscount();
        if ("nny".equals(type))  return new ActivityDiscount();

        // 多种折扣策略
        CompositeDiscount compositeDiscount;
        System.out.println("请选择冲突解决方案：1.折上折 2.最低折");
        Scanner scanner = new Scanner(System.in);
        int next = scanner.nextInt();
        if(next==1){
            compositeDiscount=new MultipleStrategy();
        }
        else{
            compositeDiscount=new SingleMinStrategy();
        }
        if(type.charAt(0)=='y')compositeDiscount.add(new VipDiscount());
        if(type.charAt(1)=='y')compositeDiscount.add(new StoreDiscount());
        if(type.charAt(2)=='y')compositeDiscount.add(new ActivityDiscount());
        return compositeDiscount;
    }

}
